package com.ynet.middleground.riskmanage.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ynet.cache.redis.IfpRedisson;
import com.ynet.middleground.riskmanage.model.DaGangModel;
import com.ynet.middleground.riskmanage.mq.consumer.BlchztConsumer;
import com.ynet.middleground.riskmanage.mq.producer.BlchztProducer;
import com.ynet.middleground.riskmanage.mq.producer.SourceProducer;
import com.ynet.middleground.riskmanage.utils.ApiUtil;

@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private IfpRedisson redisson;

    @Autowired
    private SourceProducer sourceProducer;
    @Autowired
    private BlchztProducer blchztProducer;

    @Autowired
    private BlchztConsumer blchztConsumer;
    
    @Autowired
    private DaGangModel daGangModel;

    /**
     *
     * @param flag 1或者null 写日志；0 不写日志
     * @return
     */
    @RequestMapping("/logswitch")
    public @ResponseBody String logSwitch(String flag) {
        redisson.set(ApiUtil.REDIS_KEY, flag);
        return "success";
    }
    
    /**
    * 手动从主数据获取货种信息
    * @param 
    * @return
    */
   @RequestMapping("/getMasterGoodsType")
   public @ResponseBody String getMasterGoodsTypeFromMasterData() {
       daGangModel.getMasterGoodsType();
       return "success";
   }

    @RequestMapping("/mq")
    public @ResponseBody String mqTest(String abc) {
        sourceProducer.sendMessages(abc);
        return "success";
    }

    /**
     * 测试数据，模拟全球捷运推送【入池数据】
     *
     * @return
     */
    @RequestMapping("/blch-in")
    public @ResponseBody String blchIn() {
        Map<String, Object> data = new HashMap<String, Object>() {
            {
                put("orderType", "0");
                put("orderNum", "1234");
                put("buyerName", "test_user");
                put("currency", "1");
                put("coreAmount", "1");
                put("rmbAmount", "1");
                put("invoiceSailingDate", "2020-08-17");
                put("accountsReceivableDate", "2020-08-17");
                put("supplementaryInvoiceDate", "2020-08-17");
                put("supplementaryInvoiceNo", "1324");
                put("serialNo", "1234");
                put("status", "02");
                put("reason", "success");
                put("newPoolDate", "2020-08-20");
                put("channel", "C01");
                put("gmtCreate", "2020-08-17 16:54:05");
                put("createBy", 1);
                put("gmtModified", "2020-08-17 16:54:08");
                put("modifiedBy", 1);
            }
        };
        sourceProducer.sendMessagesBlchIn(data);
        return "success";
    }

    /**
     * 测试数据，模拟全球捷运推送【出池数据】
     *
     * @return
     */
    @RequestMapping("/blch-out")
    public @ResponseBody String blchOut() {
        Map<String, Object> data = new HashMap<String, Object>() {
            {
                put("orderType", "0");
                put("orderNum", "1234");
                put("buyerName", "test_user");
                put("currency", "1");
                put("coreAmount", "1");
                put("rmbAmount", "1");
                put("invoiceSailingDate", "2020-08-17");
                put("accountsReceivableDate", "2020-08-17");
                put("accountsReceivableLatestPaymentDate", "2020-08-17");
                put("accountsReceivableBalance", "1");
                put("supplementaryInvoiceDate", "2020-08-17");
                put("supplementaryInvoiceNo", "1");
                put("serialNo", "1234");
                put("actualPaymentDate", "2020-08-17");
                put("actualPaymentAmount", "1");
                put("status", "12");
                put("reason", "success");
                put("outPoolDate", "2020-08-20");
                put("channel", "C01");
                put("gmtCreate", "2020-08-17 16:58:31");
                put("createBy", 1);
                put("gmtModified", "2020-08-17 16:58:36");
                put("modifiedBy", 1);
            }
        };
        sourceProducer.sendMessagesBlchOut(data);
        return "success";
    }

    /**
     * 测试 模拟核心发送数据
     */
    @RequestMapping("/hx-in")
    public @ResponseBody String hxIn() {
        blchztProducer.testIn();
        return "发送成功";
    }

    @RequestMapping("/hx-out")
    public @ResponseBody String hxOut() {
        blchztProducer.testOut();
        return "发送成功";
    }

    /**
     * @author liulx
     * @return
     */
    @RequestMapping("/blch-zt-in")
    @ResponseBody
    public String blchZtIn(@RequestBody Map<String, Object> msgMap) {
        blchztConsumer.inputBlcztInConsumer(msgMap);
        return "success";
    }

    /**
     * @author liulx
     * @return
     */
    @RequestMapping("/blch-zt-out")
    @ResponseBody
    public String blchZtOut(@RequestBody Map<String, Object> msgMap) {
        blchztConsumer.inputBlcztOutConsumer(msgMap);
        return "success";
    }

}
